package org.goodsl.mdd.validator;

import org.goodsl.mdd.Seg;
import org.goodsl.mdd.SingleValidResult;
import org.goodsl.mdd.Validator;

import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Simon Xiao
 * Date: 12-11-13
 * Time: 下午6:31
 * To change this template use File | Settings | File Templates.
 */
public class FutureValidator extends Validator<Seg> {

    public FutureValidator(String message){
        super(message);

    }
    @Override
    public SingleValidResult<Seg> verify(Seg variable) {
        Object value = variable.getValue();
        if(value.getClass().equals(Date.class)){
            Date date =(Date)value;
           if(date.after(new Date()))
               return new SingleValidResult<Seg>(true,"",variable,this);
           else
               return new SingleValidResult<Seg>(false,getMessage(),variable,this);
        }
        if(value.getClass().equals(Calendar.class)){
            Calendar cal = (Calendar)value;
            if(cal.after( Calendar.getInstance()))
                return new SingleValidResult<Seg>(true,"",variable,this);
            else
                return new SingleValidResult<Seg>(false,getMessage(),variable,this);
        }
        return new SingleValidResult<Seg>(false,getMessage(),variable,this);
    }
}
